package com.foreknow.animal;

public class Test {

    public void Test1(){
        Cat cat = new Cat("加菲猫",4);
        Duck duck = new Duck("唐小鸭",2);
        System.out.print(cat.getName()+
                "有"+cat.getLegNum()+"条腿，叫声是");
        cat.shout();
        System.out.print(duck.getName()+
                "有"+duck.getLegNum()+"条腿，叫声是");
        duck.shout();
    }

    public void Test2(Animal1 animal){
        System.out.print(animal.getName()+
                "有"+animal.getLegNum()+"条腿，叫声是");
        int c = animal.getName().indexOf("猫");
        if(c!=-1){
            System.out.println("喵喵喵......");
        }else{
            System.out.println("嘎嘎嘎......");
        }
    }

    public void Test3(Animal2 animal){
        System.out.print(animal.getName()+
                "有"+animal.getLegNum()+"条腿，叫声是");
    }

    public static void main(String[] args) {
        Test test1 = new Test();
        System.out.println("练习1");
        test1.Test1();

        Test test2 = new Test();
        System.out.println("练习2");
        Animal1 cat2 = new Cat1("加菲猫",4);
        test2.Test2(cat2);
        Animal1 duck2 = new Cat1("唐小鸭",2);
        test2.Test2(duck2);


        Test test3 = new Test();
        System.out.println("练习3");
        Animal2 cat3 = new Cat2("加菲猫",4);
        test3.Test3(cat3);
        cat3.shout();
        Animal2 duck3 = new Duck2("唐小鸭",2);
        test3.Test3(duck3);
        duck3.shout();
    }
}
